var Payment = (function($) {
	/*
	 * Full model, used for copying var colNames = [ 'User Id', 'Bet type',
	 * 'Date', 'Choice', 'Channel', 'Odds', 'Stake', 'Win/Lose', 'Comm', 'Affiliate
	 * WL', 'Affiliate WL', 'Affiliate Comm', 'Status' ]; var colModel =
	 * [userIdModel,transTypeModel,transDateModel,choideModel,channelIdModel,oddsModel,stakeModel,
	 * winLoseModel,commissionModel,agentWlModel,affiliateWlModel,affiliateCommModel.statusModel];
	 * 
	 */

	var monthModel = {
		name : 'month',
		index : 'month',
		width : 60
	};
	var transTypeModel = {
		name : 'trans_type',
		index : 'trans_type',
		width : 60,
		sorttype : "string"
	};
	var amountModel = {
		name : 'amount',
		index : 'amount',
		width : 90,
		sorttype : "currency"
	};
	
	return {

		initPayment : function() {
			$("#submit").click(function() {
				Payment.bindPayment();
				return false;
			});
			Affiliate.initDateRangePicker();
		},

		bindPayment : function() {

			var colNames = [ 'Month', 'Earning/Payment', 'Amount'];
			var colModel = [ monthModel, transTypeModel, amountModel ];
			var gridOption = $.extend(Affiliate.gridOption, {
				height : 500,
				colNames : colNames,
				colModel : colModel
			});

			$.blockUI();
			$.ajax( {
				type : "POST",
				url : "paymenthistoryData",
				dataType : "json",
				data : {
					fromdate : $("#fromdate").val(),
					todate : $("#todate").val()
				},
				success : function(response) {
					// Show the grid
					gridOption.data = response.Main;
					gridOption.userData = response.Total;

					$("#jqgrid-table").jqGrid('GridUnload');
					$("#jqgrid-table").jqGrid(gridOption);
					Affiliate.initColumnChooser();

				},
				complete : function() {
					$.unblockUI()
				}
			});
		}
	};
})(jQuery);
